local extension = Package("sksanying")
extension.extensionName = "jilvRem"

local U = require "packages/utility/utility"

Fk:loadTranslationTable{
  ["sksanying"] = "极略三国-三英",
  ["sk_devil1"] = "极略-三英",
  ["sk_devil2"] = "极略-三英",
}

local lvbu1 = General(extension, "sk_devil1__godlvbu", "god", 8)
lvbu1.hulao_status = 1
local lvbu2 = General(extension, "sk_devil2__godlvbu", "god", 3)
lvbu2.hulao_status = 2
local sk__wushuang = fk.CreateTriggerSkill{
  name = "sk__wushuang",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.DamageCaused},
  can_trigger = function(self, event, target, player, data)
    return target and target == player and player:hasSkill(self) and data.to ~= player and
      data.card and data.card.number % 2 == 1
  end,
  on_use = function(self, event, target, player, data)
    data.damage = 3
  end,
}
local sk__xiuluo = fk.CreateTriggerSkill{
  name = "sk__xiuluo",
  anim_type = "drawcard",
  events = {fk.TargetConfirmed},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and (data.card.trueName == "slash" or data.card:isCommonTrick()) and
      data.card.name ~= "duel" and #AimGroup:getAllTargets(data.tos) == 1
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#sk__xiuluo-invoke:::"..data.card:toLogString())
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:drawCards(1, self.name)

    room:sendLog{
      type = "#SkChangeCardSkill",
      from = player.id,
      to = { data.from },
      arg = self.name,
      arg2 = data.card:toLogString(),
      arg3 = "savage_assault",
    }

    local use = room.logic:getCurrentEvent():findParent(GameEvent.UseCard, true)
    if use ~= nil then
      local new_card = Fk:cloneCard("duel", data.card.suit, data.card.number)
      local c = table.simpleClone(data.card)
      for k, v in pairs(c) do
        if new_card[k] == nil then
          new_card[k] = v
        end
      end
      if data.card:isVirtual() then
        new_card.subcards = data.card.subcards
      else
        new_card.id = data.card.id
      end
      new_card.skillNames = data.card.skillNames
      new_card.skill = Fk.skills["duel_skill"]
      data.card = new_card
      use.data[1].card = new_card
    end
  end,
}
local sk__shenwei = fk.CreateMaxCardsSkill{
  name = "sk__shenwei",
  frequency = Skill.Compulsory,
  correct_func = function(self, player)
    return -#table.filter(Fk:currentRoom().alive_players, function (p)
      return p:hasSkill(self) and p:inMyAttackRange(player)
    end)
  end,
}
local sk__shenji = fk.CreateTargetModSkill{
  name = "sk__shenji",
  frequency = Skill.Compulsory,
  extra_target_func = function(self, player, skill)
    if skill.trueName == "slash_skill" and player:hasSkill(self) then
      return 2
    end
  end,
}
lvbu1:addSkill("sk__wushuang")
lvbu1:addSkill("mashu")
lvbu2:addSkill(sk__wushuang)
lvbu2:addSkill("mashu")
lvbu2:addSkill(sk__xiuluo)
lvbu2:addSkill(sk__shenwei)
lvbu2:addSkill(sk__shenji)
Fk:loadTranslationTable{
  ["sk_devil1__godlvbu"] = "魔吕布",
  ["#sk_devil1__godlvbu"] = "",
  ["sk_devil2__godlvbu"] = "魔吕布",
  ["#sk_devil2__godlvbu"] = "最强神话",

  ["sk__wushuang"] = "无双",
  [":sk__wushuang"] = "锁定技，你对其他角色造成伤害时，若造成伤害的牌点数为奇数，此伤害改为3点。",
  ["sk__xiuluo"] = "修罗",
  [":sk__xiuluo"] = "当你成为【杀】或普通锦囊牌的唯一目标后，你可以摸一张牌，将此牌效果改为【决斗】。",
  ["sk__shenwei"] = "神威",
  [":sk__shenwei"] = "锁定技，你攻击范围内的角色手牌上限-1。",
  ["sk__shenji"] = "神戟",
  [":sk__shenji"] = "锁定技，你使用【杀】目标上限+2。",
  ["#sk__xiuluo-invoke"] = "修罗：是否摸一张牌，将此%arg的效果改为【决斗】？",
}

local caifuren1 = General(extension, "sk_devil1__godcaifuren", "god", 8, 8, General.Female)
caifuren1.hulao_status = 1
local caifuren2 = General(extension, "sk_devil2__godcaifuren", "god", 3, 3, General.Female)
caifuren2.hulao_status = 2
local sk__dihui = fk.CreateActiveSkill{
  name = "sk__dihui",
  anim_type = "offensive",
  target_num = 2,
  card_num = 0,
  prompt = function (self, selected_cards, selected_targets)
    if #selected_targets == 0 then
      return "#sk__dihui0"
    elseif #selected_targets == 1 then
      return "#sk__dihui1:"..selected_targets[1]
    elseif #selected_targets == 2 then
      return "#sk__dihui2:"..selected_targets[1]..":"..selected_targets[2]
    end
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected)
    if #selected == 0 then
      return true
    elseif #selected == 1 then
      return Fk:currentRoom():getPlayerById(selected[1]).hp > Fk:currentRoom():getPlayerById(to_select).hp
    end
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target1 = room:getPlayerById(effect.tos[1])
    local target2 = room:getPlayerById(effect.tos[2])
    room:damage({
      from = target1,
      to = target2,
      damage = 1,
      skillName = self.name,
    })
    if target1 ~= player and player:isWounded() and not player.dead then
      room:recover({
        who = player,
        num = 1,
        recoverBy = player,
        skillName = self.name,
      })
    end
  end,
}
local sk__luansi = fk.CreateActiveSkill{
  name = "sk__luansi",
  anim_type = "control",
  target_num = 2,
  card_num = 0,
  prompt = "#sk__luansi",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected)
    local target = Fk:currentRoom():getPlayerById(to_select)
    if not target:isKongcheng() then
      if #selected == 0 then
        return true
      elseif #selected == 1 then
        return Fk:currentRoom():getPlayerById(selected[1]):canPindian(target)
      end
    end
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target1 = room:getPlayerById(effect.tos[1])
    local target2 = room:getPlayerById(effect.tos[2])
    local pindian = target1:pindian({target2}, self.name)
    for _, p in ipairs({target1, target2, player}) do
      if player.dead then return end
      if pindian.results[target2.id].winner ~= p and not p.dead then
        if p == player then
          player:drawCards(2, self.name)
        elseif not p:isNude() then
          local cards = room:askForCardsChosen(player, p, 1, 2, "he", self.name, "#sk__luansi-discard::"..p.id)
          room:throwCard(cards, self.name, p, player)
        end
      end
    end
  end,
}
local sk__huoxin = fk.CreateTriggerSkill{
  name = "sk__huoxin",
  anim_type = "control",
  frequency = Skill.Compulsory,
  events = {fk.DamageInflicted},
  can_trigger = function (self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.from and not data.from.dead
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    room:doIndicate(player.id, {data.from.id})
    local all_choices = {"sk__huoxin1:"..player.id, "sk__huoxin2"}
    local choices = table.simpleClone(all_choices)
    if data.from:isAllNude() then
      table.remove(choices, 1)
    end
    local choice = room:askForChoice(data.from, choices, self.name, nil, false, all_choices)
    if choice == "sk__huoxin2" then
      room:loseHp(data.from, 1, self.name)
      return true
    else
      local card_data = {}
      if data.from:getHandcardNum() > 0 then
        local handcards = {}
        for i = 1, data.from:getHandcardNum(), 1 do
          table.insert(handcards, -1) -- 手牌不可见
        end
        table.insert(card_data, {"$Hand", handcards})
      end
      local areas = {["$Equip"] = Player.Equip, ["$Judge"] = Player.Judge}
      for k, v in pairs(areas) do
        if #data.from.player_cards[v] > 0 then
          table.insert(card_data, {k, data.from:getCardIds(v)})
        end
      end
      local ret = room:askForPoxi(player, "sk__huoxin_get", card_data, nil, false)
      local cards = table.filter(ret, function(id) return id ~= -1 end)
      local hand_num = #ret - #cards
      if hand_num > 0 and data.from ~= player then
        table.insertTable(cards, table.random(data.from:getCardIds("h"), hand_num))
      end
      room:moveCardTo(cards, Card.PlayerHand, player, fk.ReasonPrey, self.name, nil, false, player.id)
    end
  end,
}
Fk:addPoxiMethod{
  name = "sk__huoxin_get",
  card_filter = Util.TrueFunc,
  feasible = function(selected, data)
    if data and #data == #selected then
      local areas = {}
      for _, id in ipairs(selected) do
        for _, v in ipairs(data) do
          if table.contains(v[2], id) then
            table.insertIfNeed(areas, v[2])
            break
          end
        end
      end
      return #areas == #selected
    end
  end,
  prompt = "#sk__huoxin_get",
  default_choice = function(data)
    if not data then return {} end
    local cids = table.map(data, function(v) return v[2][1] end)
    return cids
  end,
}
caifuren1:addSkill("sk__dihui")
caifuren2:addSkill(sk__dihui)
caifuren2:addSkill(sk__luansi)
caifuren2:addSkill(sk__huoxin)
Fk:loadTranslationTable{
  ["sk_devil1__godcaifuren"] = "魔蔡夫人",
  ["#sk_devil1__godcaifuren"] = "蛇蝎美人",
  ["sk_devil2__godcaifuren"] = "魔蔡夫人",
  ["#sk_devil2__godcaifuren"] = "名门妖媚",

  ["sk__dihui"] = "诋毁",
  [":sk__dihui"] = "出牌阶段限一次，你可以令一名角色对一名体力值小于其的角色造成1点伤害，若造成伤害的角色不为你，你回复1点体力。",
  ["sk__luansi"] = "乱嗣",
  [":sk__luansi"] = "出牌阶段限一次，你可以令两名角色拼点，你弃置拼点没赢的角色两张牌。若拼点赢的角色不为你，你摸两张牌。",
  ["sk__huoxin"] = "祸心",
  [":sk__huoxin"] = "锁定技，当你受到伤害时，伤害来源选择一项：1.你获得其每个区域各一张牌；2.防止此伤害，其失去1点体力。",
  ["#sk__dihui0"] = "诋毁：令一名角色对一名体力值小于其的角色造成1点伤害",
  ["#sk__dihui1"] = "诋毁：令 %src 对一名体力值小于其的角色造成1点伤害",
  ["#sk__dihui2"] = "诋毁：令 %src 对 %dest 造成1点伤害",
  ["#sk__luansi"] = "乱嗣：令两名角色拼点，你弃置没赢的角色两张牌，若不是你赢，你摸两张牌",
  ["#sk__luansi-discard"] = "乱嗣：弃置 %dest 至多两张牌",
  ["sk__huoxin1"] = "%src 获得你每个区域各一张牌",
  ["sk__huoxin2"] = "失去1点体力，防止此伤害",
  ["sk__huoxin_get"] = "祸心",
  ["#sk__huoxin_get"] = "祸心：获得其每个区域各一张牌",
}

local zhangrang1 = General(extension, "sk_devil1__godzhangrang", "god", 8)
zhangrang1.hulao_status = 1
local zhangrang2 = General(extension, "sk_devil2__godzhangrang", "god", 3)
zhangrang2.hulao_status = 2
local sk__chanxian = fk.CreateActiveSkill{
  name = "sk__chanxian",
  anim_type = "control",
  card_num = 0,
  target_num = 2,
  prompt = function (self, selected_cards, selected_targets)
    if #selected_targets == 0 then
      return "#sk__chanxian0:::"..self.interaction.data
    elseif #selected_targets == 1 then
      return "#sk__chanxian1:"..selected_targets[1].."::"..self.interaction.data
    elseif #selected_targets == 2 then
      return "#sk__chanxian2:"..selected_targets[1]..":"..selected_targets[2]..":"..self.interaction.data
    end
  end,
  interaction = function(self)
    return UI.ComboBox { choices = {"hand_card", "Field"} }
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter =function (self, to_select, selected, selected_cards, card, extra_data, player)
    if #selected == 0 then
      if self.interaction.data == "hand_card" then
        return not Fk:currentRoom():getPlayerById(to_select):isKongcheng()
      elseif self.interaction.data == "Field" then
        return #Fk:currentRoom():getPlayerById(to_select):getCardIds("ej") > 0
      end
    elseif #selected == 1 then
      if self.interaction.data == "hand_card" then
        return true
      else
        return Fk:currentRoom():getPlayerById(selected[1]):canMoveCardsInBoardTo(Fk:currentRoom():getPlayerById(to_select))
      end
    end
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target1 = room:getPlayerById(effect.tos[1])
    local target2 = room:getPlayerById(effect.tos[2])
    if self.interaction.data == "hand_card" then
      local card = room:askForCardChosen(player, target1, "h", self.name, "#sk__chanxian-card:"..target1.id..":"..target2.id)
      room:moveCardTo(card, Card.PlayerHand, target2, fk.ReasonJustMove, self.name, nil, false, player.id)
    else
      room:askForMoveCardInBoard(player, target1, target2, self.name, nil, target1)
    end
    if target1.dead or target2.dead or target1:isProhibited(target2, Fk:cloneCard("duel")) then return end
    local use = room:useVirtualCard("duel", nil, target1, target2, self.name)
    if use.damageDealt then
      for _, p in ipairs(room:getOtherPlayers(player)) do
        if player.dead then return end
        if use.damageDealt[p.id] and not p:isNude() and not p.dead then
          local card = room:askForCardChosen(player, p, "he", self.name, "#sk__chanxian-prey::"..p.id)
          room:moveCardTo(card, Card.PlayerHand, player, fk.ReasonPrey, self.name, nil, false, player.id)
        end
      end
    end
  end,
}
local sk__luanzheng = fk.CreateTriggerSkill{
  name = "sk__luanzheng",
  anim_type = "control",
  events = {fk.AfterCardTargetDeclared},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and (data.card.type == Card.TypeBasic or data.card:isCommonTrick()) and
      #player.room:getUseExtraTargets(data) > 0 and #TargetGroup:getRealTargets(data.tos) == 1 and
      player:usedSkillTimes(self.name, Player.HistoryTurn) == 0
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local tos = room:askForChoosePlayers(player, room:getUseExtraTargets(data), 1, 1,
      "#sk__luanzheng-choose:::"..data.card:toLogString(), self.name, true)
    if #tos > 0 then
      self.cost_data = tos
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    table.insert(data.tos, self.cost_data)
  end,
}
local sk__canlve = fk.CreateTriggerSkill{
  name = "sk__canlve",
  mute = true,
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      for _, move in ipairs(data) do
        if move.from and move.to and move.from ~= move.to and
          (move.from == player.id or move.to == player.id) and
          (move.toArea == Card.PlayerHand or move.toArea == Card.PlayerEquip) then
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
              if move.to == player.id and not player.room:getPlayerById(move.from).dead then
                return true
              end
              if move.from == player.id and not player.room:getPlayerById(move.to).dead and
                not player.room:getPlayerById(move.to):isNude() then
                return true
              end
            end
          end
        end
      end
    end
  end,
  on_trigger = function(self, event, target, player, data)
    local room = player.room
    local targets, dat1, dat2 = {}, {}, {}
    for _, move in ipairs(data) do
      if move.from and move.to and move.from ~= move.to and
        (move.from == player.id or move.to == player.id) and
        (move.toArea == Card.PlayerHand or move.toArea == Card.PlayerEquip) then
        for _, info in ipairs(move.moveInfo) do
          if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
            if move.to == player.id then
              table.insertIfNeed(targets, move.from)
              table.insertIfNeed(dat1, move.from)
            end
            if move.from == player.id then
              table.insertIfNeed(targets, move.to)
              table.insertIfNeed(dat2, move.to)
            end
          end
        end
      end
    end
    room:sortPlayersByAction(targets)
    for _, id in ipairs(targets) do
      if not player:hasSkill(self) then break end
      local to = room:getPlayerById(id)
      if not to.dead then
        if table.contains(dat1, id) then
          self:doCost(event, to, player, 1)
        end
        if not player:hasSkill(self) then break end
        if table.contains(dat2, id) and not to.dead and not to:isNude() then
          self:doCost(event, to, player, 2)
        end
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#sk__canlve"..data.."-invoke::"..target.id)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke(self.name)
    room:doIndicate(player.id, {target.id})
    if data == 1 then
      room:notifySkillInvoked(player, self.name, "offensive")
      room:damage{
        from = player,
        to = target,
        damage = 1,
        skillName = self.name,
      }
    else
      room:notifySkillInvoked(player, self.name, "control")
      room:askForDiscard(target, 1, 1, true, self.name, false)
    end
  end,
}
zhangrang1:addSkill("sk__chanxian")
zhangrang2:addSkill(sk__chanxian)
zhangrang2:addSkill(sk__luanzheng)
zhangrang2:addSkill(sk__canlve)
Fk:loadTranslationTable{
  ["sk_devil1__godzhangrang"] = "魔张让",
  ["#sk_devil1__godzhangrang"] = "祸乱之源",
  ["sk_devil2__godzhangrang"] = "魔张让",
  ["#sk_devil2__godzhangrang"] = "统摄天地",

  ["sk__chanxian"] = "谗陷",
  [":sk__chanxian"] = "出牌阶段限一次，你可以移动一名角色区域内一张牌，失去此牌的角色视为对获得此牌的角色使用一张【决斗】，然后你获得受到此"..
  "【决斗】伤害角色的一张牌。",
  ["sk__luanzheng"] = "乱政",
  [":sk__luanzheng"] = "每回合限一次，当一名角色使用基本牌或普通锦囊牌指定唯一目标时，你可以为此牌增加一个目标。",
  ["sk__canlve"] = "残掠",
  [":sk__canlve"] = "当你获得其他角色的牌后，你可以对其造成1点伤害；当其他角色获得你的牌后，你可以令其弃置一张牌。",
  ["#sk__chanxian0"] = "谗陷：移动一名角色%arg一张牌，失去牌的角色视为对获得牌的角色使用【决斗】，你获得受到伤害角色一张牌",
  ["#sk__chanxian1"] = "谗陷：移动 %src %arg一张牌，%src 视为对获得牌的角色使用【决斗】，你获得受到伤害角色一张牌",
  ["#sk__chanxian2"] = "谗陷：移动 %src %arg一张牌给 %dest，%src 视为对 %dest 使用【决斗】，你获得受到伤害角色一张牌",
  ["#sk__chanxian-card"] = "谗陷：选择 %src 的一张手牌移动给 %dest",
  ["#sk__chanxian-prey"] = "谗陷：获得 %dest 一张牌",
  ["#sk__luanzheng-choose"] = "乱政：你可以为%arg增加一个目标",
  ["#sk__canlve1-invoke"] = "残掠：是否对 %dest 造成1点伤害？",
  ["#sk__canlve2-invoke"] = "残掠：是否令 %dest 弃置一张牌？",
}

local weiyan1 = General(extension, "sk_devil1__godweiyan", "god", 8)
weiyan1.hulao_status = 1
local weiyan2 = General(extension, "sk_devil2__godweiyan", "god", 3)
weiyan2.hulao_status = 2
local sk__shiao = fk.CreateTriggerSkill{
  name = "sk__shiao",
  anim_type = "offensive",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and (player.phase == Player.Start or player.phase == Player.Finish)
  end,
  on_cost = function(self, event, target, player, data)
    local use = U.askForUseVirtualCard(player.room, player, "slash", nil, self.name, "#sk__shiao-invoke", true, true, false, true,
      nil, true)
    if use then
      self.cost_data = use
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    player.room:useCard(self.cost_data)
  end,
}
local sk__fangu = fk.CreateTriggerSkill{
  name = "sk__fangu",
  anim_type = "special",
  frequency = Skill.Compulsory,
  events = {fk.DamageFinished},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) then
      local turn_event = player.room.logic:getCurrentEvent():findParent(GameEvent.Turn)
      return turn_event
    end
  end,
  on_use = function(self, event, target, player, data)
    local turn_event = player.room.logic:getCurrentEvent():findParent(GameEvent.Turn)
    if turn_event then
      player:gainAnExtraTurn()
      turn_event:shutdown()
    end
  end,
}
local sk__kuangxi = fk.CreateTriggerSkill{
  name = "sk__kuangxi",
  anim_type = "offensive",
  events = {fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card.type == Card.TypeTrick and
      table.find(TargetGroup:getRealTargets(data.tos), function (id)
        return not player.room:getPlayerById(id).dead
      end)
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#sk__kuangxi-invoke:::"..data.card:toLogString())
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local targets = table.filter(TargetGroup:getRealTargets(data.tos), function (id)
      return not room:getPlayerById(id).dead
    end)
    room:sortPlayersByAction(targets)
    targets = table.map(targets, Util.Id2PlayerMapper)
    local use = room:useVirtualCard("slash", nil, player, targets, self.name, true)
    if not use.damageDealt and not player.dead then
      room:loseHp(player, 1, self.name)
    end
  end,
}
weiyan1:addSkill("sk__shiao")
weiyan2:addSkill(sk__shiao)
weiyan2:addSkill(sk__fangu)
weiyan2:addSkill(sk__kuangxi)
Fk:loadTranslationTable{
  ["sk_devil1__godweiyan"] = "魔魏延",
  ["#sk_devil1__godweiyan"] = "嗜血狂狼",
  ["sk_devil2__godweiyan"] = "魔魏延",
  ["#sk_devil2__godweiyan"] = "孤狼梦魇",

  ["sk__shiao"] = "恃傲",
  [":sk__shiao"] = "准备阶段或结束阶段，你可以视为使用【杀】。",
  ["sk__fangu"] = "反骨",
  [":sk__fangu"] = "锁定技，当你受到伤害结算后，你令当前回合结束，你执行一个额外回合。",
  ["sk__kuangxi"] = "狂袭",
  [":sk__kuangxi"] = "当你使用锦囊牌结算后，你可以视为对此牌的所有目标角色使用一张【杀】，若此【杀】未造成伤害，你失去1点体力。",
  ["#sk__shiao-invoke"] = "恃傲：你可以视为使用【杀】",
  ["#sk__kuangxi-invoke"] = "狂袭：是否视为对此%arg的所有目标角色使用一张【杀】？",
}

local dongzhuo1 = General(extension, "sk_devil1__goddongzhuo", "god", 8)
dongzhuo1.hulao_status = 1
local dongzhuo2 = General(extension, "sk_devil2__goddongzhuo", "god", 3)
dongzhuo2.hulao_status = 2
local sk__zongyu = fk.CreateTriggerSkill{
  name = "sk__zongyu",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card.type == Card.TypeTrick and player.phase == Player.Play
  end,
  on_use = function(self, event, target, player, data)
    player.room:useVirtualCard("analeptic", nil, player, player, self.name, true)
  end,
}
local sk__lingnve = fk.CreateTriggerSkill{
  name = "sk__lingnve",
  anim_type = "drawcard",
  events = {fk.DamageCaused},
  can_trigger = function(self, event, target, player, data)
    return target and target == player and player:hasSkill(self) and data.damage > 1
  end,
  on_use = function(self, event, target, player, data)
    player:drawCards(2, self.name)
    if not player.dead then
      player.room:changeMaxHp(player, 1)
    end
  end,
}
local sk__baozheng = fk.CreateTriggerSkill{
  name = "sk__baozheng",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.EventPhaseEnd},
  can_trigger = function(self, event, target, player, data)
    return target ~= player and player:hasSkill(self) and target.phase == Player.Draw and not target.dead
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:doIndicate(player.id, {target.id})
    if target:isKongcheng() then
      room:useVirtualCard("slash", nil, player, target, self.name, true)
    else
      local card = room:askForCard(target, 1, 1, false, self.name, true, ".|.|.|.|.|trick", "#sk__baozheng-invoke:"..player.id)
      if #card > 0 then
        room:moveCardTo(card, Card.PlayerHand, player, fk.ReasonGive, self.name, nil, true, target.id)
      else
        room:useVirtualCard("slash", nil, player, target, self.name, true)
      end
    end
  end,
}
local sk__nishi = fk.CreateTriggerSkill{
  name = "sk__nishi",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.from and data.from ~= player and not data.from.dead
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:doIndicate(player.id, {data.from.id})
    if #data.from:getCardIds("e") == 0 or
      not room:askForSkillInvoke(data.from, self.name, nil, "#sk__nishi-invoke:"..player.id) then
      room:useVirtualCard("slash", nil, player, data.from, self.name, true)
    end
  end,
}
local sk__hengxing = fk.CreateTriggerSkill{
  name = "sk__hengxing",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.DamageCaused},
  can_trigger = function(self, event, target, player, data)
    return target and target == player and player:hasSkill(self) and player.phase ~= Player.Play
  end,
  on_use = function(self, event, target, player, data)
    data.damage = data.damage + 1
  end,
}
dongzhuo1:addSkill("sk__zongyu")
dongzhuo1:addSkill("sk__lingnve")
dongzhuo2:addSkill(sk__zongyu)
dongzhuo2:addSkill(sk__lingnve)
dongzhuo2:addSkill(sk__baozheng)
dongzhuo2:addSkill(sk__nishi)
dongzhuo2:addSkill(sk__hengxing)
Fk:loadTranslationTable{
  ["sk_devil1__goddongzhuo"] = "魔董卓",
  ["#sk_devil1__goddongzhuo"] = "",
  ["sk_devil2__goddongzhuo"] = "魔董卓",
  ["#sk_devil2__goddongzhuo"] = "狱魔王",

  ["sk__zongyu"] = "纵欲",
  [":sk__zongyu"] = "锁定技，当你于出牌阶段使用锦囊牌后，你视为使用【酒】。",
  ["sk__lingnve"] = "凌虐",
  [":sk__lingnve"] = "当你造成伤害时，若此伤害不小于2点，你可以摸两张牌，加1点体力上限。",
  ["sk__baozheng"] = "暴政",
  [":sk__baozheng"] = "锁定技，其他角色摸牌阶段结束时，其需交给你一张锦囊牌，否则视为你对其使用【杀】。",
  ["sk__nishi"] = "逆施",
  [":sk__nishi"] = "锁定技，当你受到其他角色造成的伤害后，其需弃置装备区内所有牌，否则视为你对其使用【杀】。",
  ["sk__hengxing"] = "横行",
  [":sk__hengxing"] = "锁定技，当你于出牌阶段外造成伤害时，此伤害+1。",
  ["#sk__baozheng-invoke"] = "暴政：交给 %src 一张锦囊牌，或点“取消”视为 %src 对你使用【杀】！",
  ["#sk__nishi-invoke"] = "逆施：弃置装备区内所有牌，或点“取消”视为 %src 对你使用【杀】！",
}

local zhangjiao1 = General(extension, "sk_devil1__godzhangjiao", "god", 8)
zhangjiao1.hulao_status = 1
local zhangjiao2 = General(extension, "sk_devil2__godzhangjiao", "god", 3)
zhangjiao2.hulao_status = 2
local sk__bujiao = fk.CreateTriggerSkill{
  name = "sk__bujiao",
  anim_type = "control",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target ~= player and target.phase == Player.Start and not target.dead
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#sk__bujiao-invoke::"..target.id)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:doIndicate(player.id, {target.id})
    room:addPlayerMark(target, "@sk__taiping", 1)
    target:drawCards(1, self.name)
  end,
}
local sk__bujiao_maxcards = fk.CreateMaxCardsSkill{
  name = "#sk__bujiao_maxcards",
  main_skill = sk__bujiao,
  correct_func = function(self, player)
    if player:getMark("@sk__taiping") > 0 then
      return -#table.filter(Fk:currentRoom().alive_players, function (p)
        return p:hasSkill(sk__bujiao)
      end) * player:getMark("@sk__taiping")
    end
  end,
}
local sk__taiping = fk.CreateTriggerSkill{
  name = "sk__taiping",
  anim_type = "drawcard",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Start and
      table.find(player.room.alive_players, function (p)
        return p:getMark("@sk__taiping") > 0
      end)
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#sk__taiping-invoke")
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:doIndicate(player.id, table.map(room.alive_players, Util.IdMapper))
    local n, sum = 0, 0
    for _, p in ipairs(room:getOtherPlayers(player)) do
      n = n + p:getMark("@sk__taiping")
      room:setPlayerMark(p, "@sk__taiping", 0)
      sum = sum + p:getHandcardNum()
    end
    n = n + player:getMark("@sk__taiping")
    room:setPlayerMark(player, "@sk__taiping", 0)
    player:drawCards(n, self.name)
    if player:getHandcardNum() > sum and room:askForSkillInvoke(player, self.name, nil, "#sk__taiping-damage") then
      for _, p in ipairs(room:getOtherPlayers(player)) do
        if not p.dead then
          room:damage({
            from = player,
            to = p,
            damage = 1,
            skillName = self.name,
          })
        end
      end
    end
  end,
}
local sk__yaohuo = fk.CreateActiveSkill{
  name = "sk__yaohuo",
  anim_type = "control",
  min_card_num = 1,
  target_num = 1,
  prompt = "#sk__yaohuo",
  interaction = function(self)
    return UI.ComboBox { choices = {"sk__yaohuo1", "sk__yaohuo2"} }
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = function (self, to_select, selected,player)
    return not player:prohibitDiscard(to_select)
  end,
  target_filter =function (self, to_select, selected, selected_cards, card, extra_data, player)
    if #selected == 0 and to_select ~= player.id then
      if self.interaction.data == "sk__yaohuo1" then
        return not Fk:currentRoom():getPlayerById(to_select):isKongcheng()
      elseif self.interaction.data == "sk__yaohuo2" then
        local target = Fk:currentRoom():getPlayerById(to_select)
        return #target.player_skills > 0
        --[[return table.find(target.player_skills, function (s)
          return s:isPlayerSkill(target) and s.visible
        end)]]--
      end
    end
  end,
  feasible = function (self, selected, selected_cards)
    if #selected == 1 then
      local target = Fk:currentRoom():getPlayerById(selected[1])
      if self.interaction.data == "sk__yaohuo1" then
        return #selected_cards == target:getHandcardNum()
      elseif self.interaction.data == "sk__yaohuo2" then
        return #selected_cards == #table.filter(target.player_skills, function (s)
          return s:isPlayerSkill(target) and s.visible
        end)
      end
    end
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    room:throwCard(effect.cards, self.name, player, player)
    if player.dead or target.dead then return end
    if self.interaction.data == "sk__yaohuo1" then
      if not target:isKongcheng() then
        room:moveCardTo(target:getCardIds("h"), Card.PlayerHand, player, fk.ReasonPrey, self.name, nil, false, player.id)
      end
    else
      local all_skills, get = {}, {}
      for _, s in ipairs(target.player_skills) do
        if s:isPlayerSkill(player) and s.visible then
          table.insert(all_skills, s.name)
          if not player:hasSkill(s, true) then
            table.insert(get, s.name)
          end
        end
      end
      if #all_skills == 0 then return end
      local mark = player:getTableMark(self.name)
      mark[string.format("%.0f", target.id)] = mark[string.format("%.0f", target.id)] or {}
      local m = mark[string.format("%.0f", target.id)]
      m[1] = m[1] or {}
      table.insertTableIfNeed(m[1], all_skills)
      m[2] = m[2] or {}
      table.insertTableIfNeed(m[2], get)
      mark[string.format("%.0f", target.id)] = {m[1], m[2]}
      room:setPlayerMark(player, self.name, mark)
      room:handleAddLoseSkills(target, "-"..table.concat(all_skills, "|-"), nil, true, false)
      room:handleAddLoseSkills(player, get, nil, true, false)
    end
  end,
}
local sk__yaohuo_delay = fk.CreateTriggerSkill{
  name = "#sk__yaohuo_delay",
  mute = true,
  events = {fk.BeforeTurnStart, fk.Death},
  can_trigger = function (self, event, target, player, data)
    if player:getMark("sk__yaohuo") ~= 0 then
      local mark = player:getTableMark("sk__yaohuo")
      return mark[string.format("%.0f", target.id)]
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local mark = player:getTableMark("sk__yaohuo")
    local m = mark[string.format("%.0f", target.id)]
    local all_skills, get = table.simpleClone(m[1]), table.simpleClone(m[2])
    mark[string.format("%.0f", target.id)] = nil
    room:setPlayerMark(player, "sk__yaohuo", mark)
    room:handleAddLoseSkills(target, all_skills, nil, true, false)
    room:handleAddLoseSkills(player, "-"..table.concat(get, "|-"), nil, true, false)
  end,
}
local sk__sanzhi = fk.CreateTriggerSkill{
  name = "sk__sanzhi",
  anim_type = "special",
  events = {fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) and #player:getTableMark(self.name) == 3 then
      player.room:setPlayerMark(player, self.name, 0)
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:doIndicate(player.id, table.map(room:getOtherPlayers(player), Util.IdMapper))
    for _, p in ipairs(room:getOtherPlayers(player)) do
      room:addPlayerMark(p, "@sk__taiping", 1)
    end
  end,

  refresh_events = {fk.CardUseFinished},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:hasSkill(self, true)
  end,
  on_refresh = function(self, event, target, player, data)
    local mark = player:getTableMark(self.name)
    table.insertIfNeed(mark, data.card.type)
    player.room:setPlayerMark(player, self.name, mark)
  end,
}
sk__bujiao:addRelatedSkill(sk__bujiao_maxcards)
sk__yaohuo:addRelatedSkill(sk__yaohuo_delay)
zhangjiao1:addSkill("sk__bujiao")
zhangjiao1:addSkill("sk__taiping")
zhangjiao2:addSkill(sk__bujiao)
zhangjiao2:addSkill(sk__taiping)
zhangjiao2:addSkill(sk__yaohuo)
zhangjiao2:addSkill(sk__sanzhi)
Fk:loadTranslationTable{
  ["sk_devil1__godzhangjiao"] = "魔张角",
  ["#sk_devil1__godzhangjiao"] = "大贤良师",
  ["sk_devil2__godzhangjiao"] = "魔张角",
  ["#sk_devil2__godzhangjiao"] = "妖众燎原",

  ["sk__bujiao"] = "布教",
  [":sk__bujiao"] = "其他角色准备阶段，你可以令其摸一张牌并获得一枚“太平”标记。一名角色每有一枚“太平”标记，其手牌上限-1。",
  ["sk__taiping"] = "太平",
  [":sk__taiping"] = "准备阶段，你可以弃置所有角色的“太平”标记，你摸等量的牌，然后若你的手牌数大于所有其他角色手牌数之和，你可以对所有其他"..
  "角色各造成1点伤害。",
  ["sk__yaohuo"] = "妖惑",
  [":sk__yaohuo"] = "出牌阶段限一次，你可以指定一名其他角色并选择一项：1.弃置其手牌数的牌，获得其所有手牌；2.弃置其技能数的牌，偷取其所有"..
  "技能直到其回合开始或其死亡。",
  ["sk__sanzhi"] = "三治",
  [":sk__sanzhi"] = "当你使用三张不同类别的牌后，你可以令所有其他角色各获得一枚“太平”标记。",
  ["#sk__bujiao-invoke"] = "布教：是否令 %dest 摸一张牌并获得一枚“太平”标记？",
  ["@sk__taiping"] = "太平",
  ["#sk__taiping-invoke"] = "太平：是否弃置所有角色的“太平”标记，你摸等量的牌？",
  ["#sk__taiping-damage"] = "太平：是否对所有其他角色各造成1点伤害？",
  ["#sk__yaohuo"] = "妖惑：弃置等量的牌，获得一名角色所有手牌，或偷取其所有技能直到其回合开始或其死亡！",
  ["sk__yaohuo1"] = "手牌",
  ["sk__yaohuo2"] = "技能",
}

local simayi1 = General(extension, "sk_devil1__godsimayi", "god", 8)
simayi1.hulao_status = 1
local simayi2 = General(extension, "sk_devil2__godsimayi", "god", 3)
simayi2.hulao_status = 2
local sk__bolve = fk.CreateTriggerSkill{
  name = "sk__bolve",
  anim_type = "special",
  frequency = Skill.Compulsory,
  events = {fk.BeforeTurnStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local mark = player:getTableMark("sk__renji")
    for _, kingdom in ipairs({"wei", "shu", "wu"}) do
      mark[kingdom] = mark[kingdom] or 1
    end

    local skills = {}
    for _, general in ipairs(room.general_pile) do
      local g = Fk.generals[general]
      if mark[g.kingdom] then
        skills[g.kingdom] = skills[g.kingdom] or {}
        table.insertTableIfNeed(skills[g.kingdom], g:getSkillNameList())
      end
    end

    math.randomseed(tonumber(tostring(os.time()):reverse():sub(1, 6)))
    local get = {}
    for kingdom, skill_list in pairs(skills) do
      skill_list = table.filter(skill_list, function(s)
        return not player:hasSkill(s, true)
      end)
      if #skill_list > 0 then
        table.insertTableIfNeed(get, table.random(skill_list, mark[kingdom]))
      end
    end
    room:setPlayerMark(player, self.name, get)
    room:handleAddLoseSkills(player, get, nil, true, false)
  end,

  refresh_events = {fk.BeforeTurnStart},
  can_refresh = function(self, event, target, player, data)
    return target == player and #player:getTableMark(self.name) > 0
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    room:handleAddLoseSkills(player, "-"..table.concat(player:getTableMark(self.name), "|-"), nil, true, false)
    room:setPlayerMark(player, self.name, 0)
  end,
}
local sk__renji = fk.CreateTriggerSkill{
  name = "sk__renji",
  anim_type = "masochism",
  events = {fk.Damaged},
  on_use = function(self, event, target, player, data)
    player:drawCards(1, self.name)
    if player.dead then return end
    if data.from then
      local mark = player:getTableMark(self.name)
      mark[data.from.kingdom] = (mark[data.from.kingdom] or 1) + 1
      player.room:setPlayerMark(player, self.name, mark)
    end
  end,
}
local sk__biantian = fk.CreateTriggerSkill{
  name = "sk__biantian",
  anim_type = "special",
  frequency = Skill.Compulsory,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target ~= player and target.phase == Player.Judge and not target.dead
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:doIndicate(player.id, {target.id})
    local judge = {
      who = target,
      reason = "lightning",
      pattern = ".|2~9|spade",
    }
    room:judge(judge)
    if target.dead then return end
    if judge.card.suit == Card.Spade and judge.card.number > 1 and judge.card.number < 10 then
      room:damage{
        to = target,
        damage = 3,
        damageType = fk.ThunderDamage,
        skillName = "lightning_skill",
      }
    end
  end,
}
local sk__tianyou = fk.CreateTriggerSkill{
  name = "sk__tianyou",
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) and player.phase == Player.Finish then
      local events = player.room.logic:getActualDamageEvents(999, function (e)
        local damage = e.data[1]
        if damage.skillName == "lightning_skill" then
          return true
        end
      end, Player.HistoryGame)
      if #events == 0 then
        self.cost_data = 0
        return player:isWounded()
      else
        self.cost_data = #events
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if self.cost_data == 0 then
      room:recover({
        who = player,
        num = 1,
        recoverBy = player,
        skillName = self.name,
      })
    else
      player:drawCards(self.cost_data, self.name)
    end
  end,
}
simayi1:addSkill("sk__bolve")
simayi2:addSkill(sk__bolve)
simayi2:addSkill(sk__renji)
simayi2:addSkill(sk__biantian)
simayi2:addSkill(sk__tianyou)
Fk:loadTranslationTable{
  ["sk_devil1__godsimayi"] = "魔司马懿",
  ["#sk_devil1__godsimayi"] = "三分归晋",
  ["sk_devil2__godsimayi"] = "魔司马懿",
  ["#sk_devil2__godsimayi"] = "三分归晋",

  ["sk__bolve"] = "博略",
  [":sk__bolve"] = "锁定技，回合开始前，你随机获得魏/蜀/吴势力武将的技能各一个，直到你下回合开始。",
  ["sk__renji"] = "忍忌",
  [":sk__renji"] = "当你受到伤害后，你可以摸一张牌，然后本局游戏你发动〖博略〗时额外随机获得一个与伤害来源势力相同武将的技能。",
  ["sk__biantian"] = "变天",
  [":sk__biantian"] = "锁定技，其他角色判定阶段开始时，你令其进行一次【闪电】判定。",
  ["sk__tianyou"] = "天佑",
  [":sk__tianyou"] = "锁定技，结束阶段，若X为0，你回复1点体力；若X大于0，你摸X张牌（X为本局游戏所有角色受到【闪电】伤害的次数）。",

  ["$sk__bolve1"] = "老夫想到一件有趣之事。",
  ["$sk__bolve2"] = "无用之物，老夫毫无兴趣。",
  ["$sk__bolve3"] = "杀人伎俩，偶尔一用，无妨。",
  ["$sk__bolve4"] = "此种事态，老夫早有准备。",
  ["$sk__renji1"] = "老夫也不得不认真起来了。",
  ["$sk__renji2"] = "你们，是要置老夫于死地吗？",
  ["$sk__renji3"] = "休要聒噪，吵得老夫头疼！",
  ["$sk__biantian"] = "雷起，嗬啊！",
  ["$sk__tianyou"] = "好好看着吧！",
  ["~sk_devil__godsimayi"] = "",
}

local sunhao1 = General(extension, "sk_devil1__godsunhao", "god", 8)
sunhao1.hulao_status = 1
local sunhao2 = General(extension, "sk_devil2__godsunhao", "god", 3)
sunhao2.hulao_status = 2
local sk__mingzheng = fk.CreateTriggerSkill{
  name = "sk__mingzheng",
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  events = {fk.DrawNCards, fk.PropertyChange, fk.Damaged},
  can_trigger = function (self, event, target, player, data)
    if player:hasSkill(self) then
      if event == fk.DrawNCards then
        return true
      elseif target == player then
        if event == fk.PropertyChange then
          return data.general
        elseif event == fk.Damaged then
          return true
        end
      end
    end
  end,
  on_use = function (self, event, target, player, data)
    if event == fk.DrawNCards then
      if target == player then
        data.n = data.n + 2
      else
        data.n = data.n + 1
      end
    else
      local room = player.room
      local n = #room.logic:getEventsOfScope(GameEvent.Turn, 1, function (e)
        return e.data[1] == player
      end, Player.HistoryGame)
      if n > 0 then
        player:drawCards(n, self.name)
      end
      if not player.dead then
        room:handleAddLoseSkills(player, "-sk__mingzheng|sk__shisha", nil, true, false)
      end
    end
  end,
}
local sk__shisha = fk.CreateTriggerSkill{
  name = "sk__shisha",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card.trueName == "slash" and
      not player.room:getPlayerById(data.to):isNude()
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(data.to)
    local cards = table.random(to:getCardIds("he"), math.random(3))
    room:throwCard(cards, self.name, to, player)
  end,
}
local sk__huangyin = fk.CreateTriggerSkill{
  name = "sk__huangyin",
  anim_type = "drawcard",
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      for _, move in ipairs(data) do
        if move.moveReason == fk.ReasonDiscard then
          if move.from and move.from ~= player.id and move.proposer and move.proposer == player.id then
            for _, info in ipairs(move.moveInfo) do
              if (info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip) and
                table.contains(player.room.discard_pile, info.cardId) then
                return true
              end
            end
          end
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = {}
    for _, move in ipairs(data) do
      if move.moveReason == fk.ReasonDiscard then
        if move.from and move.from ~= player.id and move.proposer and move.proposer == player.id then
          for _, info in ipairs(move.moveInfo) do
            if (info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip) and
              table.contains(room.discard_pile, info.cardId) then
              table.insertIfNeed(cards, info.cardId)
            end
          end
        end
      end
    end
    room:moveCardTo(table.random(cards), Card.PlayerHand, player, fk.ReasonJustMove, self.name, nil, true, player.id)
  end,
}
local sk__zuijiu = fk.CreateActiveSkill{
  name = "sk__zuijiu",
  anim_type = "offensive",
  card_num = 0,
  target_num = 0,
  prompt = function (self)
    return "#sk__zuijiu:::"..(Self:usedSkillTimes(self.name, Player.HistoryPhase) + 1)
  end,
  can_use = function(self, player)
    return #table.filter(player:getCardIds("he"), function (id)
      return not player:prohibitDiscard(id)
    end) > player:usedSkillTimes(self.name, Player.HistoryPhase)
  end,
  card_filter = Util.FalseFunc,
  on_use = function(self, room, effect)
    math.randomseed(tonumber(tostring(os.time()):reverse():sub(1, 6)))
    local player = room:getPlayerById(effect.from)
    local cards = table.filter(player:getCardIds("he"), function (id)
      return not player:prohibitDiscard(id)
    end)
    cards = table.random(cards, player:usedSkillTimes(self.name, Player.HistoryPhase))
    room:throwCard(cards, self.name, player, player)
    if player.dead then return end
    local names = {}
    if not player:prohibitUse(Fk:cloneCard("analeptic")) then
      table.insert(names, "analeptic")
    end
    if not player:prohibitUse(Fk:cloneCard("slash")) and
      table.find(room:getOtherPlayers(player), function (p)
        return player:canUseTo(Fk:cloneCard("slash"), p, {bypass_times = true})
      end) then
      table.insert(names, "slash")
    end
    if #names == 0 then return end
    local name = table.random(names)
    if name == "analeptic" then
      room:useVirtualCard("analeptic", nil, player, player, self.name, true)
    else
      local targets = table.filter(room:getOtherPlayers(player), function (p)
        return player:canUseTo(Fk:cloneCard("slash"), p, {bypass_times = true})
      end)
      room:useVirtualCard("slash", nil, player, table.random(targets), self.name, true)
    end
  end,
}
local sk__guiming = fk.CreateTriggerSkill{
  name = "sk__guiming",
  anim_type = "defensive",
  frequency = Skill.Limited,
  events = {fk.EnterDying},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.dying and player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:recover({
      who = player,
      num = math.min(#room.alive_players, player.maxHp) - player.hp,
      recoverBy = player,
      skillName = self.name,
    })
    local n = #room.alive_players
    for _, p in ipairs(room:getOtherPlayers(player)) do
      if not p:isNude() and not p.dead then
        local cards = table.random(p:getCardIds("he"), math.random(n))
        room:throwCard(cards, self.name, p, player)
      end
    end
  end,
}
sunhao1:addSkill("sk__mingzheng")
sunhao1:addRelatedSkill("sk__shisha")
sunhao2:addSkill(sk__mingzheng)
sunhao2:addRelatedSkill(sk__shisha)
sunhao2:addSkill(sk__huangyin)
sunhao2:addSkill(sk__zuijiu)
sunhao2:addSkill(sk__guiming)
Fk:loadTranslationTable{
  ["sk_devil1__godsunhao"] = "魔孙皓",
  ["#sk_devil1__godsunhao"] = "",
  ["sk_devil2__godsunhao"] = "魔孙皓",
  ["#sk_devil2__godsunhao"] = "末世暴君",

  ["sk__mingzheng"] = "明政",
  [":sk__mingzheng"] = "锁定技，其他角色摸牌阶段摸牌数+1，你摸牌阶段摸牌数+2。当你变身后或受到伤害后，你摸X张牌（X为你进行过的回合数），"..
  "失去〖明政〗，获得〖嗜杀〗",
  ["sk__shisha"] = "嗜杀",
  [":sk__shisha"] = "锁定技，当你使用【杀】指定目标后，你随机弃置目标角色一至三张牌。",
  ["sk__huangyin"] = "荒淫",
  [":sk__huangyin"] = "当你弃置其他角色的牌后，你可以获得其中随机一张牌。",
  ["sk__zuijiu"] = "醉酒",
  [":sk__zuijiu"] = "出牌阶段，你可以随机弃置X张牌（X为本阶段发动此技能次数），随机视为使用一张不计次数的【酒】或【杀】。",
  ["sk__guiming"] = "归命",
  [":sk__guiming"] = "限定技，当你进入濒死状态时，你可以回复至X点体力，弃置所有其他角色随机X张牌（X为存活角色数）。",
  ["#sk__zuijiu"] = "醉酒：你可以弃置随机%arg张牌，随机视为使用一张不计次数的【酒】或【杀】",
}

local diaochan1 = General(extension, "sk_devil1__goddiaochan", "god", 8, 8, General.Female)
diaochan1.hulao_status = 1
local diaochan2 = General(extension, "sk_devil2__goddiaochan", "god", 3, 3, General.Female)
diaochan2.hulao_status = 2
local sk__meihuo = fk.CreateActiveSkill{
  name = "sk__meihuo",
  anim_type = "control",
  min_card_num = 1,
  target_num = 1,
  prompt = "#sk__meihuo",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = function(self, to_select, selected)
    return Fk:currentRoom():getCardArea(to_select) == Card.PlayerHand
  end,
  target_filter =function (self, to_select, selected, selected_cards, card, extra_data, player)
    return #selected == 0 and to_select ~= player.id and Fk:currentRoom():getPlayerById(to_select):isMale()
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    room:moveCardTo(effect.cards, Card.PlayerHand, target, fk.ReasonGive, self.name, nil, false, player.id)
    if player.dead or target.dead or target:isKongcheng() then return end
    local tos = room:askForChoosePlayers(player, table.map(room:getOtherPlayers(target), Util.IdMapper), 1, 999,
      "#sk__meihuo-choose::"..target.id, self.name, false)
    room:sortPlayersByAction(tos)
    local cards = table.simpleClone(target:getCardIds("h"))
    while not target.dead do
      cards = table.filter(cards, function(id)
        local card = Fk:getCardById(id)
        return (card.trueName == "slash" or card:isCommonTrick()) and table.contains(target:getCardIds("h"), id)
      end)
      if #cards == 0 or target.dead then return end
      room:delay(1000)
      local card = Fk:getCardById(table.random(cards))
      if card.skill:getMinTargetNum() == 2 or not target:canUse(card) then
        room:moveCardTo(card, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, self.name, nil, true, target.id)
      else
        tos = table.filter(tos, function (id)
          return not room:getPlayerById(id).dead
        end)
        if #tos == 0 then
          room:moveCardTo(card, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, self.name, nil, true, target.id)
        else
          room:useCard({
            from = target.id,
            tos = table.map(tos, function (id) return {id} end),
            card = card,
            extraUse = true,
          })
        end
      end
    end
  end,
}
local sk__yaoyan = fk.CreateTriggerSkill{
  name = "sk__yaoyan",
  anim_type = "control",
  frequency = Skill.Compulsory,
  events = {fk.TargetConfirming},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) and (data.card.type == Card.TypeBasic or data.card:isCommonTrick()) and
      data.from ~= player.id and not table.contains(AimGroup:getAllTargets(data.tos), data.from) then
      local from = player.room:getPlayerById(data.from)
      return not from.dead and not from:isProhibited(from, data.card)
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    room:sendLog{
      type = "#AddTargetsBySkill",
      from = player.id,
      to = {data.from},
      arg = self.name,
      arg2 = data.card:toLogString(),
    }
    AimGroup:addTargets(room, data, {data.from})
  end,
}
local sk__miluan = fk.CreateTriggerSkill{
  name = "sk__miluan",
  anim_type = "masochism",
  events = {fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and
      table.find(player.room:getOtherPlayers(player), function (p) return not p:isKongcheng() end)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:doIndicate(player.id, table.map(room:getOtherPlayers(player), Util.IdMapper))
    local moves = {}
    for _, p in ipairs(room:getOtherPlayers(player)) do
      if not p:isKongcheng() then
        table.insert(moves, {
          ids = p:getCardIds("h"),
          from = p.id,
          to = player.id,
          toArea = Card.PlayerHand,
          moveReason = fk.ReasonPrey,
          skillName = self.name,
          proposer = player.id,
        })
      end
    end
    room:moveCards(table.unpack(moves))
    if player.dead or player:getHandcardNum() < 2 or #room:getOtherPlayers(player) == 0 then return end

    room:delay(1000)
    math.randomseed(tonumber(tostring(os.time()):reverse():sub(1, 6)))
    local targets = room:getOtherPlayers(player)
    local cards = table.random(player:getCardIds("h"), player:getHandcardNum() // 2)
    local id_mapper = {}
    for _, id in ipairs(cards) do
      local n = math.random(#targets)
      id_mapper[n] = id_mapper[n] or {}
      table.insert(id_mapper[n], id)
    end
    moves = {}
    for i = 1, #targets, 1 do
      if id_mapper[i] then
        table.insert(moves, {
          ids = id_mapper[i],
          from = player.id,
          to = targets[i].id,
          toArea = Card.PlayerHand,
          moveReason = fk.ReasonGive,
          skillName = self.name,
          proposer = player.id,
        })
      end
    end
    room:moveCards(table.unpack(moves))
  end,
}
diaochan1:addSkill("sk__meihuo")
diaochan2:addSkill(sk__meihuo)
diaochan2:addSkill(sk__yaoyan)
diaochan2:addSkill(sk__miluan)
Fk:loadTranslationTable{
  ["sk_devil1__goddiaochan"] = "魔貂蝉",
  ["#sk_devil1__goddiaochan"] = "妖狐之魅",
  ["sk_devil2__goddiaochan"] = "魔貂蝉",
  ["#sk_devil2__goddiaochan"] = "妖狐之魅",

  ["sk__meihuo"] = "魅惑",
  [":sk__meihuo"] = "出牌阶段限一次，你可以将任意张手牌交给一名男性角色，然后选择除其以外任意名角色，此男性角色以这些角色为目标随机使用"..
  "其当前手牌中所有【杀】和普通锦囊牌。",
  ["sk__yaoyan"] = "妖颜",
  [":sk__yaoyan"] = "锁定技，当你成为其他角色使用基本牌或普通锦囊牌的目标时，你令其也成为此牌的目标。",
  ["sk__miluan"] = "迷乱",
  [":sk__miluan"] = "当你受到伤害后，你可以获得所有其他角色的手牌，然后将一半的手牌（向下取整）随机分配给其他角色。",
  ["#sk__meihuo"] = "魅惑：将任意张手牌交给一名角色，然后以你指定的任意名角色为目标使用其手牌中所有【杀】和普通锦囊牌！",
  ["#sk__meihuo-choose"] = "魅惑：指定 %dest 使用牌的目标",
}

local yuanshao1 = General(extension, "sk_devil1__godyuanshao", "god", 8)
yuanshao1.hulao_status = 1
local yuanshao2 = General(extension, "sk_devil2__godyuanshao", "god", 3)
yuanshao2.hulao_status = 2
local sk__mojian = fk.CreateTriggerSkill{
  name = "sk__mojian",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    if target == player then
      if player.phase == Player.Start then
        return player:hasSkill(self) and player:canUse(Fk:cloneCard("archery_attack"))
      elseif player.phase == Player.Finish then
        return player:getMark("sk__mojian-turn") > 0 and player:canUse(Fk:cloneCard("archery_attack")) and not player.dead
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local card = Fk:cloneCard("archery_attack")
    card.skillName = self.name
    local use = {
      from = player.id,
      card = card,
    }
    room:useCard(use)
    if player.phase == Player.Start and use.extra_data and use.extra_data.sk__mojian and not player.dead then
      room:setPlayerMark(player, "sk__mojian-turn", 1)
    end
  end,

  refresh_events = {fk.CardRespondFinished},
  can_refresh = function (self, event, target, player, data)
    return target == player and data.card.trueName == "jink" and data.responseToEvent and data.responseToEvent.card and
      table.contains(data.responseToEvent.card.skillNames, self.name)
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    local e = room.logic:getCurrentEvent():findParent(GameEvent.UseCard)
    if e then
      local use = e.data[1]
      if table.contains(use.card.skillNames, self.name) then
        use.extra_data = use.extra_data or {}
        use.extra_data.sk__mojian = true
      end
    end
  end,
}
local sk__zhuzai = fk.CreateTriggerSkill{
  name = "sk__zhuzai",
  mute = true,
  frequency = Skill.Compulsory,
  events = {fk.DamageInflicted, fk.DamageCaused},
  can_trigger = function(self, event, target, player, data)
    return target and target == player and player:hasSkill(self) and data.card and data.card.type == Card.TypeTrick
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke(self.name)
    if event == fk.DamageInflicted then
      room:notifySkillInvoked(player, self.name, "defensive")
      data.damage = data.damage - 1
    elseif event == fk.DamageCaused then
      room:notifySkillInvoked(player, self.name, "offensive")
      data.damage = data.damage + 1
    end
  end,
}
local sk__duoji = fk.CreateTriggerSkill{
  name = "sk__duoji",
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  events = {fk.Death},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and data.damage and data.damage.from == player
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if not target:isKongcheng() then
      room:moveCardTo(target:getCardIds("h"), Card.PlayerHand, player, fk.ReasonPrey, self.name, nil, false, player.id)
    end
    if player.dead then return end
    local skills = table.map(table.filter(target.player_skills, function(s)
      return s:isPlayerSkill(target) and s.visible and not player:hasSkill(s, true)
    end), function(s)
      return s.name
    end)
    if #skills > 0 then
      room:handleAddLoseSkills(player, skills, nil, true, false)
    end
  end,
}
yuanshao1:addSkill("sk__mojian")
yuanshao2:addSkill(sk__mojian)
yuanshao2:addSkill(sk__zhuzai)
yuanshao2:addSkill(sk__duoji)
Fk:loadTranslationTable{
  ["sk_devil1__godyuanshao"] = "魔袁绍",
  ["#sk_devil1__godyuanshao"] = "魔君",
  ["sk_devil2__godyuanshao"] = "魔袁绍",
  ["#sk_devil2__godyuanshao"] = "魔君",

  ["sk__mojian"] = "魔箭",
  [":sk__mojian"] = "锁定技，准备阶段，你视为使用【万箭齐发】，若有角色打出【闪】响应此牌，本回合结束阶段，你视为使用【万箭齐发】。",
  ["sk__zhuzai"] = "主宰",
  [":sk__zhuzai"] = "锁定技，你受到锦囊牌造成的伤害-1，你使用锦囊牌造成的伤害+1。",
  ["sk__duoji"] = "夺冀",
  [":sk__duoji"] = "锁定技，当你杀死其他角色时，你获得其所有手牌和技能。",
}

local sunluban1 = General(extension, "sk_devil1__godsunluban", "god", 8, 8, General.Female)
sunluban1.hulao_status = 1
local sunluban2 = General(extension, "sk_devil2__godsunluban", "god", 3, 3, General.Female)
sunluban2.hulao_status = 2
local sk__quanqing = fk.CreateActiveSkill{
  name = "sk__quanqing",
  anim_type = "control",
  card_num = 1,
  target_num = 1,
  prompt = "#sk__quanqing",
  can_use = function(self, player)
    return not player:isKongcheng()
  end,
  card_filter = function(self, to_select, selected,player)
    return #selected == 0 and Fk:currentRoom():getCardArea(to_select) == Player.Hand and
      not table.contains(player:getTableMark("sk__quanqing_cards-phase"), to_select)
  end,
  target_filter =function (self, to_select, selected, selected_cards, card, extra_data, player)
    return #selected == 0 and to_select ~= player.id and
      not table.contains(player:getTableMark("sk__quanqing_players-phase"), to_select)
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    local mark = player:getTableMark("sk__quanqing_players-phase")
    table.insert(mark, target.id)
    room:setPlayerMark(player, "sk__quanqing_players-phase", mark)
    mark = player:getTableMark("sk__quanqing_cards-phase")
    table.insert(mark, effect.cards[1])
    room:setPlayerMark(player, "sk__quanqing_cards-phase", mark)
    local num = Fk:getCardById(effect.cards[1]).number
    player:showCards(effect.cards)
    if target.dead then return end
    local pattern = ".|14"
    if num < 13 then
      pattern = ".|"..tostring(num + 1).."~13"
    end
    if target:isNude() or
      #room:askForDiscard(target, 1, 1, true, self.name, true, pattern, "#sk__quanqing-discard:"..player.id.."::"..num) == 0 then
      if player.dead then return end
      if player:getMark("sk__guhuo_cards") == 0 then
        mark = U.getUniversalCards(room, "bt")
        room:setPlayerMark(player, "sk__guhuo_cards", mark)
      end
      room:setPlayerMark(player, "sk__quanqing_target", target.id)
      local success, dat = room:askForUseActiveSkill(player, "sk__quanqing_active", "#sk__quanqing-choose::"..target.id, false)
      room:setPlayerMark(player, "sk__quanqing_target", 0)
      if success then
        local card = Fk:cloneCard(Fk:getCardById(dat.cards[1]).name)
        card.skillName = self.name
        room:useCard{
          from = target.id,
          tos = table.map(dat.targets, function(id) return {id} end),
          card = card,
        }
        if player:isWounded() and not player.dead then
          room:recover({
            who = player,
            num = 1,
            recoverBy = player,
            skillName = self.name,
          })
        end
      end
    end
  end,
}
local sk__quanqing_active = fk.CreateActiveSkill{
  name = "sk__quanqing_active",
  expand_pile = function(self,player)
    return player:getTableMark("sk__guhuo_cards")
  end,
  card_num = 1,
  card_filter = function(self, to_select, selected,player)
    if #selected > 0 then return false end
    local mark = player:getTableMark("sk__guhuo_cards")
    if table.contains(mark, to_select) then
      local name = Fk:getCardById(to_select).name
      local card = Fk:cloneCard(name)
      card.skillName = "sk__quanqing"
      local target = Fk:currentRoom():getPlayerById(player:getMark("sk__quanqing_target"))
      return target:canUse(card, {bypass_times = true}) and not target:prohibitUse(card)
    end
  end,
  target_filter =function (self, to_select, selected, selected_cards, card, extra_data, player)
    if #selected_cards == 0 then return false end
    local card = Fk:cloneCard(Fk:getCardById(selected_cards[1]).name)
    card.skillName = "sk__quanqing"
    local target = Fk:currentRoom():getPlayerById(player:getMark("sk__quanqing_target"))
    if card.skill:getMinTargetNum() == 0 or #selected >= card.skill:getMaxTargetNum(target, card) then return false end
    return not target:isProhibited(Fk:currentRoom():getPlayerById(to_select), card) and
    card.skill:modTargetFilter(to_select, selected, player:getMark("sk__quanqing_target"), card, true)
  end,
  feasible = function(self, selected, selected_cards,player)
    if #selected_cards == 0 then return false end
    local card = Fk:cloneCard(Fk:getCardById(selected_cards[1]).name)
    card.skillName = "sk__quanqing"
    local target = Fk:currentRoom():getPlayerById(player:getMark("sk__quanqing_target"))
    return #selected >= card.skill:getMinTargetNum() and #selected <= card.skill:getMaxTargetNum(target, card)
  end,
}
local sk__raomeng = fk.CreateTriggerSkill{
  name = "sk__raomeng",
  anim_type = "control",
  frequency = Skill.Compulsory,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target ~= player and target.phase == Player.Judge and not target.dead and
      #target:getCardIds("j") == 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:doIndicate(player.id, {target.id})
    local judge = {
      who = target,
      reason = "indulgence",
      pattern = ".|.|spade,club,diamond",
    }
    room:judge(judge)
    local result = judge.card
    if result.suit ~= Card.Heart then
      target:skip(Player.Play)
    end
  end,
}
local sk__yongjie = fk.CreateTriggerSkill{
  name = "sk__yongjie",
  anim_type = "offensive",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Finish and
      table.find(player.room:getOtherPlayers(player), function (p)
        return #player.room.logic:getActualDamageEvents(1, function(e)
          local damage = e.data[1]
          return damage.from == p and damage.to == player
        end, Player.HistoryGame) > 0
      end)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local targets = table.map(table.filter(room:getOtherPlayers(player), function (p)
      return #room.logic:getActualDamageEvents(1, function(e)
        local damage = e.data[1]
        return damage.from == p and damage.to == player
      end, Player.HistoryGame) > 0
    end), Util.IdMapper)
    local tos = room:askForChoosePlayers(player, targets, 1, 999, "#sk__yongjie-choose", self.name, true)
    if #tos > 0 then
      self.cost_data = {tos = tos}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:sortPlayersByAction(self.cost_data.tos)
    local targets = table.map(self.cost_data.tos, Util.Id2PlayerMapper)
    for _, p in ipairs(targets) do
      if not p.dead then
        local n = #room.logic:getActualDamageEvents(999, function(e)
          local damage = e.data[1]
          return damage.from == p and damage.to == player
        end, Player.HistoryGame)
        if #room:askForDiscard(p, n, n, true, self.name, true, nil, "#sk__yongjie-discard:::"..n) < n then
          room:changeMaxHp(p, -1)
        end
      end
    end
  end,
}
Fk:addSkill(sk__quanqing_active)
sunluban1:addSkill("sk__quanqing")
sunluban2:addSkill(sk__quanqing)
sunluban2:addSkill(sk__raomeng)
sunluban2:addSkill(sk__yongjie)
Fk:loadTranslationTable{
  ["sk_devil1__godsunluban"] = "魔孙鲁班",
  ["#sk_devil1__godsunluban"] = "梦魇",
  ["sk_devil2__godsunluban"] = "魔孙鲁班",
  ["#sk_devil2__godsunluban"] = "梦魇",

  ["sk__quanqing"] = "权倾",
  [":sk__quanqing"] = "出牌阶段对每名角色限一次，你可以展示一张本阶段未以此法展示过的手牌并选择一名其他角色，其选择一项：1.弃置一张点数大于"..
  "此牌的牌；2.其视为使用一张牌名和目标由你选择的任意基本牌或普通锦囊牌，然后你回复1点体力。",
  ["sk__raomeng"] = "扰梦",
  [":sk__raomeng"] = "锁定技，其他角色的判定阶段开始时，若其判定区内没有牌，你令其进行【乐不思蜀】判定。",
  ["sk__yongjie"] = "永劫",
  [":sk__yongjie"] = "结束阶段，你可以选择任意名对你造成过伤害的其他角色，这些角色依次选择一项：1.弃置X张牌（X为其对你造成伤害的次数）；"..
  "2.减1点体力上限。",
  ["#sk__quanqing"] = "权倾：展示一张手牌，令一名角色选择弃一张点数更大的牌或视为使用你指定牌名和目标的牌",
  ["#sk__quanqing-discard"] = "权倾：弃置一张点数大于%arg的牌，否则视为使用一张 %src 指定牌名和目标的牌",
  ["#sk__quanqing-choose"] = "权倾：选择 %dest 视为使用的牌和目标",
  ["sk__quanqing_active"] = "权倾",
  ["#sk__yongjie-choose"] = "永劫：令任意名角色选择其弃置对你造成伤害次数的牌或减1点体力上限",
  ["#sk__yongjie-discard"] = "永劫：请弃置%arg张牌，否则减1点体力上限",
}

local caocao1 = General(extension, "sk_devil1__godcaocao", "god", 8)
caocao1.hulao_status = 1
local caocao2 = General(extension, "sk_devil2__godcaocao", "god", 3)
caocao2.hulao_status = 2
local sk__weiwu = fk.CreateTriggerSkill{
  name = "sk__weiwu",
  anim_type = "masochism",
  events = {fk.Damaged},
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:drawCards(2, self.name)
    if data.card and room:getCardArea(data.card) == Card.Processing and
      room:askForSkillInvoke(player, self.name, nil, "#sk__weiwu-invoke:::"..data.card:toLogString()) then
      local cards = data.card:isVirtual() and data.card.subcards or {data.card.id}
      table.insertTable(cards, table.filter(room.discard_pile, function (id)
        return Fk:getCardById(id).trueName == data.card.trueName
      end))
      room:moveCardTo(cards, Card.PlayerHand, player, fk.ReasonJustMove, self.name, nil, true, player.id)
    end
  end,
}
local sk__duzun = fk.CreateTriggerSkill{
  name = "sk__duzun",
  anim_type = "control",
  frequency = Skill.Compulsory,
  events = {fk.TurnStart},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target ~= player and not target.dead and player:getMark("sk__duzun_"..target.id) < 2
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:doIndicate(player.id, {target.id})
    room:addPlayerMark(player, "sk__duzun_"..target.id, 1)
    local choices, all_choices = {"sk__duzun3"}, {"sk__duzun1", "sk__duzun2", "sk__duzun3"}
    local card = Fk:cloneCard("slash")
    local n = card.skill:getMaxUseTime(target, Player.HistoryPhase, card, nil) or 0
    if n > 0 then
      table.insert(choices, "sk__duzun1")
    end
    if player:getMark(MarkEnum.SkDrawNCards) + 2 > 0 then
      table.insert(choices, "sk__duzun2")
    end
    table.insert(choices, "sk__duzun3")
    local choice = room:askForChoice(target, choices, self.name, "#sk__duzun-choice:"..player.id, false, all_choices)
    if choice == "sk__duzun1" then
      room:setPlayerMark(target, MarkEnum.SlashResidue, target:getMark(MarkEnum.SlashResidue) - 1)
      room:addPlayerMark(player, MarkEnum.SlashResidue, 1)
    elseif choice == "sk__duzun2" then
      room:setPlayerMark(target, MarkEnum.SkDrawNCards, target:getMark(MarkEnum.SkDrawNCards) - 1)
      room:addPlayerMark(player, MarkEnum.SkDrawNCards, 1)
    else
      room:changeMaxHp(target, -1)
      if not player.dead then
        room:changeMaxHp(player, 1)
      end
    end
  end,
}
local sk__longbian = fk.CreateTriggerSkill{
  name = "sk__longbian",
  anim_type = "special",
  events = {fk.TurnStart},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) then
      local choices, nums = {}, {}
      local card = Fk:cloneCard("slash")
      local n = card.skill:getMaxUseTime(player, Player.HistoryPhase, card, nil) or 0
      if n > 0 then
        table.insert(choices, "sk__duzun1")
      end
      table.insert(nums, n)
      if player:getMark(MarkEnum.SkDrawNCards) + 2 > 0 then
        table.insert(choices, "sk__duzun2")
      end
      table.insert(nums, math.max(player:getMark(MarkEnum.SkDrawNCards) + 2, 0))
      table.insert(choices, "sk__duzun3")
      table.insert(nums, player.maxHp)
      if #choices > 1 then
        self.cost_data = {choices, nums}
        return true
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local choices = player.room:askForChoices(player, self.cost_data[1], 2, 2, self.name,
      "#sk__longbian-invoke:::"..table.concat(self.cost_data[2], ","), true, false, {"sk__duzun1", "sk__duzun2", "sk__duzun3"})
    if #choices == 2 then
      self.cost_data = {choices, self.cost_data[2]}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local nums = self.cost_data[2]
    if table.contains(self.cost_data[1], "sk__duzun1") then
      if table.contains(self.cost_data[1], "sk__duzun2") then
        local n = nums[1] - nums[2]
        if n ~= 0 then
          room:setPlayerMark(player, MarkEnum.SlashResidue, player:getMark(MarkEnum.SlashResidue) - n)
          room:setPlayerMark(player, MarkEnum.SkDrawNCards, player:getMark(MarkEnum.SkDrawNCards) + n)
        end
        room:changeMaxHp(player, 1)
      else
        local n = nums[1] - player.maxHp
        if n ~= 0 then
          room:setPlayerMark(player, MarkEnum.SlashResidue, player:getMark(MarkEnum.SlashResidue) - n)
          room:changeMaxHp(player, n)
        end
        if not player.dead then
          room:addPlayerMark(player, MarkEnum.SkDrawNCards, 1)
        end
      end
    else
      local n = nums[2] - player.maxHp
      if n ~= 0 then
        room:setPlayerMark(player, MarkEnum.SkDrawNCards, player:getMark(MarkEnum.SkDrawNCards) - n)
        room:changeMaxHp(player, n)
      end
      if not player.dead then
        room:addPlayerMark(player, MarkEnum.SlashResidue, 1)
      end
    end
  end,
}
caocao1:addSkill("sk__weiwu")
caocao2:addSkill(sk__weiwu)
caocao2:addSkill(sk__duzun)
caocao2:addSkill(sk__longbian)
Fk:loadTranslationTable{
  ["sk_devil1__godcaocao"] = "魔曹操",
  ["#sk_devil1__godcaocao"] = "",
  ["sk_devil2__godcaocao"] = "魔曹操",
  ["#sk_devil2__godcaocao"] = "龙变",

  ["sk__weiwu"] = "魏武",
  [":sk__weiwu"] = "当你受到伤害后，你可以摸两张牌，然后若造成此伤害的渠道为实体的【杀】或普通锦囊牌，你可以获得此牌和弃牌堆中所有同名牌。",
  ["sk__duzun"] = "独尊",
  [":sk__duzun"] = "锁定技，每名角色限两次，其他角色回合开始时，其须选择一项-1，你对应项+1：出牌阶段使用【杀】次数上限；摸牌阶段摸牌数；"..
  "体力上限。",
  ["sk__longbian"] = "龙变",
  [":sk__longbian"] = "回合开始时，你可以令你大于0的两项互换，然后另一项+1：出牌阶段使用【杀】次数上限；摸牌阶段摸牌数；体力上限。",
  ["#sk__weiwu-invoke"] = "魏武：是否获得%arg及弃牌堆中所有同名牌？",
  ["#sk__duzun-choice"] = "独尊：选择一项，你的此项数值-1，%src 此项数值+1",
  ["#sk__longbian-invoke"] = "龙变：你可以选择两项数值交换，未选择的项数值+1<br>（当前数值分别为%arg）",
  ["sk__duzun1"] = "出牌阶段使用【杀】次数",
  ["sk__duzun2"] = "摸牌阶段摸牌数",
  ["sk__duzun3"] = "体力上限",
}

local zoushi1 = General(extension, "sk_devil1__godzoushi", "god", 8, 8, General.Female)
zoushi1.hulao_status = 1
local zoushi2 = General(extension, "sk_devil2__godzoushi", "god", 3, 3, General.Female)
zoushi2.hulao_status = 2
local sk__huoshi = fk.CreateTriggerSkill{
  name = "sk__huoshi",
  anim_type = "control",
  frequency = Skill.Compulsory,
  events = {fk.AfterCardTargetDeclared},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target ~= player and
      (data.card.type == Card.TypeBasic or data.card:isCommonTrick()) and data.tos and
      (#player.room:getUseExtraTargets(data) > 0 or
      (not table.contains(TargetGroup:getRealTargets(data.tos), target.id) and not target:isProhibited(target, data.card)))
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local targets = room:getUseExtraTargets(data)
    if not table.contains(TargetGroup:getRealTargets(data.tos), target.id) and not target:isProhibited(target, data.card) then
      table.insert(targets, target.id)
    end
    local to = table.random(targets)
    room:doIndicate(target.id, {to})
    table.insert(data.tos, {to})
  end,
}
local sk__yinzi = fk.CreateTriggerSkill{
  name = "sk__yinzi",
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  events = {fk.AfterCardsMove, fk.HpRecover},
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) then return end
    local turn_event = player.room.logic:getCurrentEvent():findParent(GameEvent.Turn)
    if turn_event == nil then return end
    if event == fk.AfterCardsMove and player:isWounded() then
      for _, move in ipairs(data) do
        if move.to and move.to ~= player.id and move.toArea == Card.PlayerHand and
          player.room:getPlayerById(move.to).phase == Player.NotActive and
          not table.contains(player:getTableMark("sk__yinzi1-turn"), move.to) then
          self.cost_data = move.to
          return true
        end
      end
    elseif event == fk.HpRecover and target ~= player then
      return target.phase == Player.NotActive and not table.contains(player:getTableMark("sk__yinzi2-turn"), target.id)
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    if event == fk.AfterCardsMove and player:isWounded() then
      room:addTableMark(player, "sk__yinzi1-turn", self.cost_data)
      room:recover{
        who = player,
        num = 1,
        recoverBy = player,
        skillName = self.name,
      }
    elseif event == fk.HpRecover then
      room:addTableMark(player, "sk__yinzi2-turn", target.id)
      player:drawCards(2, self.name)
    end
  end,
}
local sk__mowu = fk.CreateTriggerSkill{
  name = "sk__mowu",
  anim_type = "control",
  events = {fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and (data.card.type == Card.TypeBasic or data.card:isCommonTrick()) and data.tos and
      not (data.extra_data and data.extra_data.sk__mowu) then
      if target == player then
        return table.find(TargetGroup:getRealTargets(data.tos), function (id)
          return id ~= player.id
        end)
      else
        return table.contains(TargetGroup:getRealTargets(data.tos), player.id)
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#sk__mowu-invoke:::"..data.card:toLogString())
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local targets = TargetGroup:getRealTargets(data.tos)
    table.insertIfNeed(targets, target.id)
    room:sortPlayersByAction(targets)
    for _, id in ipairs(targets) do
      local p = room:getPlayerById(id)
      if not p.dead then
        p:drawCards(1, self.name)
      end
    end
    if table.find(TargetGroup:getRealTargets(data.tos), function (id)
      return not room:getPlayerById(id).dead
    end) then
      data.extra_data = data.extra_data or {}
      data.extra_data.sk__mowu = true
      room:useCard(data)
    end
  end,
}
zoushi1:addSkill("sk__huoshi")
zoushi2:addSkill(sk__huoshi)
zoushi2:addSkill(sk__yinzi)
zoushi2:addSkill(sk__mowu)
Fk:loadTranslationTable{
  ["sk_devil1__godzoushi"] = "魔邹氏",
  ["#sk_devil1__godzoushi"] = "妖媚之殃",
  ["sk_devil2__godzoushi"] = "魔邹氏",
  ["#sk_devil2__godzoushi"] = "妖媚之殃",

  ["sk__huoshi"] = "祸世",
  [":sk__huoshi"] = "锁定技，当其他角色使用基本牌或普通锦囊牌指定目标时，你令随机一名不是此牌目标的角色也成为此牌的目标（包括使用者）。",
  ["sk__yinzi"] = "淫恣",
  [":sk__yinzi"] = "锁定技，每回合对每名角色限一次，当其他角色于其回合外获得牌后，你回复1点体力；当其他角色于其回合外回复体力后，你摸两张牌。",
  ["sk__mowu"] = "魔舞",
  [":sk__mowu"] = "当其他角色对你/你对其他角色使用基本牌或普通锦囊牌结算后，你可以令此牌使用者和目标各摸一张牌，令此牌额外结算一次。",
  ["#sk__mowu-invoke"] = "魔舞：是否令此%arg的使用者和目标各摸一张牌，然后额外结算一次？",
}

return extension
